<?php
/**
 * 首页数据读取类
 * Class Index
 */
class IndexController extends Controller{
    private $M_news;
    private $M_trends;
    private $M_summarys;
    private $M_comments;
    private $M_sources;
    /**
     * 构造方法
     * 初始化
     */
    public function __construct(){
        $this->M_news = Model::getInstance('news');
        $this->M_trends = Model::getInstance('trends');
        $this->M_summarys = Model::getInstance('summarys');
        $this->M_comments = Model::getInstance('comments');
        $this->M_sources = Model::getInstance('sources');
    }

    /**
     * 首页
     */
    public function index(){
        $page = (int)$this->input()->get('page',1);
        //首页新闻列表
        $list = $this->M_news->getNewListByCategoryId($page,15);
        //首页编辑推荐列表
        $new_rem_index = $this->M_news->getRecommendIndexList();
        //新闻流列表
        $trend_arr = $this->M_trends->getTrendList();
        //新闻流用的的来源
        $source_ids = array();
        foreach((array)$trend_arr as $k => $v){
            $source_ids[] = $v['source_id'];
        }
        $source_ids = array_unique($source_ids);
        if(!empty($source_ids)){
            $source_arr = $this->M_sources->mulitGetSourceInfo($source_ids);
            $new_source_arr = array();
            foreach((array)$source_arr as $k => $v){
                $new_source_arr[$v['source_id']] = $v['title'];
            }
        }

        //首页摘要列表
        $summary_arr = $this->M_summarys->getRecommendIndexList();
        //首页评论列表
        $comment_rem_index = $this->M_comments->getRecommendIndexList();

        //热门评论新闻（最佳策略暂定为 点击浏览量 访问量上去后修改，根据用户喜欢修改）
        $top_new_id = $this->M_comments->getTopByCommentType(1,6);
        $top_new_arr = $this->M_news->mulitGetNewInfo($top_new_id);

        $data = array(
            'list'=>$list,
            'trendList'=>$trend_arr,
            'sourceList'=>$new_source_arr,
            'summaryList'=>$summary_arr,
            'new_rem_index'=>$new_rem_index,
            'commentRemList'=>$comment_rem_index,
            'topNewList'=>$top_new_arr
        );
        Template::show('index/index.php',$data);
    }
}

?>